﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.Reflection;
using System.Linq;

namespace MolineSoftware.DrupalXmlRpc.Classes
{
    /// <summary>
    /// Provides attibute values for Drupal Service.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public sealed class DrupalServiceAttribute : Attribute
    {
        #region | Private Properties
        private string serviceKey;
        private string serviceDomain;
        #endregion

        #region | Constructor |

        /// <summary>
        /// Initializes a new instance of <see cref="DrupalServiceAttribute"/>
        /// </summary>
        /// <param name="serviceKey">The Service Key specified in Drupal</param>
        /// <param name="serviceDomain">The Service Domain specified in Drupal</param>
        public DrupalServiceAttribute(string serviceKey, string serviceDomain)
            : base()
        {
            this.serviceKey = serviceKey;
            this.serviceDomain = serviceDomain;
        }
        //public DrupalServiceAttribute(

           
        #endregion

        #region | Public Properties |
        /// <summary>
        /// Gets the Service Key set in Drupal.
        /// </summary>
        public string ServiceKey { get { return this.serviceKey; } }

        /// <summary>
        /// Gets the Service Domain set in Drupal
        /// </summary>
        public string ServiceDomain { get { return this.serviceDomain; } }
        #endregion

        #region | Public Static Methods

        /// <summary>
        /// Returns <see cref="DrupalServiceAttribute"/> from classObject
        /// </summary>
        /// <param name="classObject">The <see cref="object"/> that contains 
        ///  <see cref="DrupalServiceAttribute"/> values.</param>
        /// <returns><see cref="DrupalServiceAttribute"/></returns>
        public static DrupalServiceAttribute Get(object classObject)
        {
            if (classObject == null)
            {
                throw new ArgumentNullException("classObject");
            }

            DrupalServiceAttribute dsa = (DrupalServiceAttribute)classObject.GetType().
                GetCustomAttributes(typeof(DrupalServiceAttribute), false).SingleOrDefault();

            return dsa;
        }

        #endregion

    }
}
